/*  VisualGroup JavaScript prototype Classes, version draf
 *  (c) 2006 Bill Vison <vison_ruan@126.com>
 *
 *
/*--------------------------------------------------------------------------*/
Vsg.Dialog.General = Class.create();

Vsg.Dialog.General.prototype.initialize = function() {
	
	var url = "about:blank";
	var width = 450;
	var height = 300;
	var title = "Default Dialog Title";	
	var $windowName = "";
	
	// save window property
	var properties = new Array();
	
	// save window user data
	var userDatas = new Array();	

	// -----------------  set commond status bar -------------------

	this.setHeight = function(arg) {
		height = arg;
	}
	
	this.setWidth = function(arg) {
		width = arg;
	}
	
	this.setUrl = function(arg) {
		url = arg;
	}
	
	this.setTitle = function(arg) {
		title = arg;
	}
	
	this.setStatusbar = function($arg) {
		var $feature = new Object();
		$feature.name = "status";
		$feature.value = $arg;
		properties.push($feature);
	}
	
	this.setTitlebar = function($arg) {
		var $feature = new Object();
		$feature.name = "titlebar";
		$feature.value = $arg;
		properties.push($feature);

	}
	
	// ------------------------------------
	
	this.setUserData = function(name , value) {
		var data = new Object();
		data.name = name;
		data.value = value;
		userDatas.push(data);
	}
	
	this.setWinFeature = function(arg0,arg1) {
		var feature = new Object();
		feature.name = arg0;
		feature.value = arg1;
		properties.push(feature);
	}
	
	this.setWinName = function($name) {
		$windowName = $name;
	}
	
	
	
	function getValue(name) {
		var value = null;
		for (index in properties) {
			if (properties[index].name == name) {
				value = properties[index].value;
			}
		}
		return value;
	}
	
	

	function show() {
		
		var windowX = Math.ceil( (window.screen.width  - width) / 2 );
		var windowY = Math.ceil( (window.screen.height - height) / 2 );
		
		
		var styleStr = "width="+width+"px,height="+height+"px";
		
		styleStr+=",left="+windowX+"px,top="+windowY+"px";
		//styleStr+=",screenX="+windowX+",screenY="+windowY;
		
		// set toolbar feature
		var feaToolBar = getValue("toolbar");
		if (feaToolBar == null) {
			styleStr+=",toolbar=no";
		} else {
			styleStr+=",toolbar="+feaToolBar;
		}
		
		var feaLocation = getValue("location");
		if (feaLocation == null) {
			styleStr+=",location=no";
		} else {
			styleStr+=",location="+feaLocation;
		}
		
		var feaChannelMode = getValue("channelmode");
		if (feaChannelMode == null) {
			styleStr+=",channelmode=no";
		} else {
			styleStr+=",channelmode="+feaChannelMode;
		}		
		
		var feaDirectories = getValue("directories");
		if (feaDirectories == null) {
			styleStr+=",directories=no";
		} else {
			styleStr+=",directories="+feaDirectories;
		}
		
		var feaStatus = getValue("status");
		if (feaStatus == null) {
			styleStr+=",status=no";
		} else {
			styleStr+=",status="+feaStatus;
		}
		
		var feaMenuBar = getValue("menubar");
		if (feaMenuBar == null) {
			styleStr+=",menubar=no";
		} else {
			styleStr+=",menubar="+feaMenuBar;
		}
		
		var feaScrollbar = getValue("scrollbar");
		if (feaScrollbar == null) {
			styleStr+=",scrollbar=no";
		} else {
			styleStr+=",scrollbar="+feaScrollbar;
		}
		
		var feaResizable = getValue("resizable");
		if (feaResizable == null) {
			styleStr+=",resizable=no";
		} else {
			styleStr+=",resizable="+feaResizable;
		}
		
		var popupWin = window.open(url,$windowName,styleStr);
		
		var popupDoc = popupWin.document;
		
		popupDoc.onreadystatechange = onReadyStateChange;
		
		//popupDoc.title = title;
		setPassArgment();
		
		// pass user data to popup window
		window.popupUserData = userDatas;	
		
	}
	this.show = show;

	// handler for document readystate change
	function onReadyStateChange() {
		if (document.readyState == "complete") {
			document.title = title;
		}
	}
	

	function setPassArgment() {
		var openArgs = new Array();
		
		// set properties
		var obj = new Object();
		obj.name = "title";
		obj.value = title;
		openArgs.push(obj);
		
		var widthObj = new Object();
		widthObj.name = "width";
		widthObj.value = width;
		openArgs.push(widthObj);

		var heightObj = new Object();
		heightObj.name = "height";
		heightObj.value = height;
		openArgs.push(heightObj);
		
		var urlObj = new Object();
		urlObj.name = "url";
		urlObj.value = url;
		openArgs.push(urlObj);
		
		window.popupArgument = openArgs;
		
		
	}

}

